package com.utils;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

import org.springframework.web.multipart.MultipartFile;

public class UploadUtils {
        private static final String BASE_PATH="D:\\upload\\";   //图片上传位置
        private static final String SERVER_PATH="http://localhost:8080/upload/";   //图片访问路径
        public static String upload(MultipartFile file) {
        	String filename=file.getOriginalFilename();
        	String uuid=UUID.randomUUID().toString().replace("_"," ");
        	String newFilename=uuid+"-"+filename;
        	File image=new File(BASE_PATH,newFilename);
			try {
				file.transferTo(image);
			}catch(IOException e) {
				return null;
			}
			return SERVER_PATH+newFilename;

        }
}
